package com.appsindy.reserv.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;

import com.appsindy.reserv.bo.Customer;
import com.appsindy.reserv.service.ReservationServices;
import com.appsindy.reserv.vo.Info;

public class TestAction extends ActionSupport {
	
	protected final Logger log = Logger.getLogger(getClass());
	
	private ReservationServices reservationServices;

	private List<Customer> customerList;
	private List<Info> infoList;
	
	public String execute(){
		try{
			Customer cust = getReservationServices().getCustomer(2);
			log.info("[TestAction.execute] Id = " + cust.getId() + ", Name = " + cust.getName());
		} catch(Exception e){
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String list(){
		try{
			List<Customer> list = getReservationServices().getAllCustomers();
			setCustomerList(list);
		} catch(Exception e){
			e.printStackTrace();
		}
		return "list";
	}
	
	public String hello123(){
		log.info("TestAction.hello123");
		List<Info> list = new ArrayList<Info>();
		for(int i=1; i<11; i++){
			Info info = new Info();
			info.setId(i);
			info.setName("Name " + i);
			list.add(info);
		}
		setInfoList(list);
		return "hello";
	}
	
	public String timePeriodView(){
		log.info("TestAction.timePeriodView");
		return "timePeriod";
	}
	
	public ReservationServices getReservationServices() {
		return reservationServices;
	}
	public void setReservationServices(ReservationServices reservationServices) {
		this.reservationServices = reservationServices;
	}

	public List<Customer> getCustomerList() {
		return customerList;
	}
	public void setCustomerList(List<Customer> customerList) {
		this.customerList = customerList;
	}
	
	public void setInfoList(List<Info> infoList){
		this.infoList = infoList;
	}
	public List<Info> getInfoList(){
		return infoList;
	}
	
}
